//package com.soxing.braindata.scheduler;
//
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.soxing.braindata.common.util.MD5Util;
//import com.soxing.braindata.dao.entity.Email;
//import com.soxing.braindata.dao.entity.UserInfo;
//import com.soxing.braindata.dao.entity.UserInfoExt;
//import com.soxing.braindata.dao.service.IEmailService;
//import com.soxing.braindata.dao.service.IUserInfoExtService;
//import com.soxing.braindata.domain.vo.UserVo;
//
//import com.soxing.common.utils.log.LogHelper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Configuration;
//
//import javax.annotation.Resource;
//import java.util.Date;
//import java.util.Random;
//
//@Slf4j
//@Configuration
//public class EmailScheduler {
//
//    @Value("${email.account}")
//    private String EmailAccount;
//
//    @Value("${email.password}")
//    private String EmailPassword;
//
//    @Resource
//    private IEmailService emailService;
//
//    @Resource
//    private IUserInfoExtService userInfoExtService;
//
//    private void sendEmail(UserInfo userInfo)
//    {
//        Date now = new Date();
//        Email email = new Email();
//
//        StringBuilder password = new StringBuilder();
//        Random random = new Random();
//        for (int i = 0; i < 6; i++) {
//            password.append(random.nextInt(10));
//        }
//
//
//        String template = "Dear %username%<br><br>Your password of WeBrain account has been changed as: <br><br>Your user name is: %username%<br>Your temporary password is: %password%<br><br>If you made this change, you’ll need to get back into your account and reset your password at http://webrain.uestc.edu.cn/ as soon as possible.<br><br>------------------------<br>Please do NOT reply to this email with questions about the use of WeBrain, or with problems that you encounter when using it: instead please contact us as soon for any problems. More details about WeBrain can be found at <a href=\"https://webrain.uestc.edu.cn/\" style=\"\">https://webrain.uestc.edu.cn/</a>.<br><br>All the best,<br>WeBrain Team<br>--------------------<br><a href=\"https://webrain.uestc.edu.cn/\" style=\"\">https://webrain.uestc.edu.cn/</a><br><br>";
//        template = template.replaceAll("%username%", userInfo.getUserNum());
//        template = template.replaceAll("%password%", password.toString());
//
//        email.setSendUser(EmailAccount);
//        email.setToUser(userInfo.getUserEmail());
//        email.setUserName(userInfo.getUserName());//以后还用的话改成usernum
//        email.setTitle("WeBrain Password Reset");
//        email.setContent(template);
//        email.setStatus(0);
//        email.setCreateTime(now);
//        email.setSendTime(now);
//        email.setSendTimes(0);
//
//        try {
//            // String pwd = EncryptUtil.encrypt(password.toString(),
//            // webSystemParameterService.getDesKey());
//            String pwd = MD5Util.getMD5(password.toString());
//
//            emailService.save(email);
//            //mapper.insertSelective(email);
//
////            UserInfo record = new UserInfo();
////            record.setId(user.getId());
////            record.setPassword(pwd);
////            userInfoService.updateByPrimaryKeySelective(record);
//            UserInfoExt userInfoExt = new UserInfoExt();
//            userInfoExt.setUserNum(userInfo.getUserNum());
//            userInfoExt.setUserPwd(pwd);
//            userInfoExtService.update(userInfoExt,new LambdaQueryWrapper<UserInfoExt>().eq(UserInfoExt::getUserNum,userInfo.getUserNum()));
//        } catch (Exception e) {
//            log.error("sendEmail fail", e);
//        }
//
//    }
//
//}
